package com.jacky.components.controller;

import com.jfoenix.controls.JFXSnackbar;
import com.jfoenix.controls.JFXSnackbarLayout;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.layout.Background;
import javafx.scene.layout.Pane;
import javafx.util.Duration;

public class SnackBarMessageController {

    @FXML
    private Pane pane;
    @FXML
    void errorMessage(ActionEvent event) {
        error("Something wrong, Please Try Again");
    }

    private void error(String msg) {
        JFXSnackbarLayout snackbarLayout = new JFXSnackbarLayout(msg);
        snackbarLayout.setPrefSize(400,100);
        JFXSnackbar snackbar = new JFXSnackbar(pane);
        snackbar.setPrefWidth(600);
//        snackbar.translateXProperty().bind(snackbarLayout.widthProperty().divide(2).subtract(pane.widthProperty().divide(2)));
        snackbar.fireEvent(new JFXSnackbar.SnackbarEvent(
                snackbarLayout,
                Duration.seconds(2), null));
    }
}
